﻿using System;
using System.Web;

namespace MvcFriendlyModule
{
    public class MvcFriendlyModule : IHttpModule
    {
        #region IHttpModule Members

        void IHttpModule.Dispose()
        {
        }

        void IHttpModule.Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        #endregion

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            if (app.Context.Response.ContentType == "text/html")
            {
                app.Context.Response.Filter =
                    new StripNamingContainerStream(
                        new StripViewStateStream(
                            app.Context.Response.Filter
                        )
                    );
            }
        }
    }
}